<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增谈心谈话记录')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-studenttalk-add">
            <div class="form-group">
                <label class="col-sm-2 control-label">教师姓名：</label>
                <div class="col-sm-4">
                    <input class="form-control" id="teachername" name="teachername" type="text" placeholder="请输入教师姓名" required/>
                </div>
                <label class="col-sm-2 control-label">所属部门：</label>
                <div class="col-sm-4">
                    <select name="teacherorg" class="form-control m-b" th:with="type=${@dict.getType('sys_dept_list')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">学生姓名：</label>
                <div class="col-sm-4">
                    <input class="form-control" id="stuname" name="stuname" type="text" placeholder="请输入学生姓名" required />
                </div>
                <label class="col-sm-2 control-label">学生性别：</label>
                <div class="col-sm-4">
                    <select name="stusex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">学生班级：</label>
                <div class="col-sm-4">
                    <input class="form-control" id="stuclass" name="stuclass" type="text" placeholder="请输入学生班级" required />
                </div>
                <label class="col-sm-2 control-label">联系方式：</label>
                <div class="col-sm-4">
                    <input class="form-control" id="stutell" name="stutell" type="text" placeholder="请输入家长联系方式" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">谈话时间：</label>
                <div class="col-sm-4">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="talktime" class="form-control" placeholder="请选择谈话时间" type="text" required />
                    </div>
                </div>
                <label class="col-sm-2 control-label">谈话地点：</label>
                <div class="col-sm-4">
                        <input class="form-control" id="talkplace" name="talkplace" type="text" placeholder="请输入谈话地点" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">受帮扶学生情况：</label>
                <div class="col-sm-9">
                    <textarea class="form-control" cols="10" rows="6" name="talkcontent" id="talkcontent" placeholder="受帮扶学生情况（学习、生活、思想）。。。" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">帮扶措施及效果：</label>
                <div class="col-sm-9">
                    <textarea class="form-control" cols="10" rows="6" name="talkresult" id="talkresult" placeholder="请输入帮扶措施及效果。。。。" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">谈话照片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="talkimg">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="talkimg" name="file" type="file">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "student/studenttalk"
        $("#form-studenttalk-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-studenttalk-add').serialize());
            }
        }

        $("input[name='talktime']").datetimepicker({
            format: "yyyy-mm-dd hh:mm:ss",
            autoclose: true
        });

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                    	var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败！");
                    		}
                    	});
                    }
                }
            });
        });
    </script>
</body>
</html>